// Quantitative Angiogram Analysis System
//
// Copyright ?Ping Zou, 2006
// sg71.cherub@gmail.com

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using eee.Sheffield.PZ.Math;

namespace eee.Sheffield.PZ.QAAS
{
    public class DrawCircles : PZDraw
    {
        #region Fields
        private float _radius = 3;
        private bool _isSolidCircle = false;
        //private double _width;
        //private double _height;
        #endregion

        #region Properties
        public bool IsSolidCircle { set { _isSolidCircle = value; } get { return _isSolidCircle; } }
        #endregion

        #region constructor
        public DrawCircles(Graphics g, double width, double height) : base(g) 
        {
            _width = width;
            _height = height;
        } // DrawCircles()
        #endregion

        #region override base class methods
        /// <summary>
        /// draw circles 
        /// </summary>
        public override void Draw()
        {
            int count = _sourceArray.Length;
            for (int i = 0; i < count; i ++)
            {
                PointF graphPoint = GetGraphCoordinate((PointF)_sourceArray[i]);
                if (_isSolidCircle)
                    _graphic.FillEllipse(_solidRedBrush, graphPoint.X - _radius, graphPoint.Y - _radius, _radius, _radius);
                else
                    _graphic.DrawEllipse(_redPen, graphPoint.X - _radius, graphPoint.Y - _radius, _radius, _radius);
            }
        } // Draw()

        /// <summary>
        /// source array is a PointF array
        /// </summary>
        /// <param name="sourceArray"></param>
        public override void SetSource(object[] sourceArray)
        {
            bool isPointF = true;
            int count = sourceArray.Length;
            double maxX = PZMath_machine.PZMath_DBL_MIN;
            double maxY = PZMath_machine.PZMath_DBL_MIN;
            double minX = PZMath_machine.PZMath_DBL_MAX;
            double minY = PZMath_machine.PZMath_DBL_MAX;

            for (int i = 0; i < count; i++)
            {
                if (sourceArray[i] is PointF)
                {
                    float xr = ((PointF)sourceArray[i]).X;
                    float yr = ((PointF)sourceArray[i]).Y;
                    maxX = xr > maxX ? xr : maxX;
                    minX = xr < minX ? xr : minX;
                    maxY = yr > maxY ? yr : maxY;
                    minY = yr < minY ? yr : minY;                   
                }
                else
                {
                    isPointF = false;
                    break;
                }
            }

            if (isPointF)
            {
                _sourceArray = sourceArray;
                Set(_width, _height, maxX, minX, maxY, minY);
            }
            else
                throw new ApplicationException("DrawCircles::SetSource(), source array is not PointF array.");
        } // SetSource()
        #endregion
    }
}
